import * as EmSDK from '../util/emSDK';
import H5Api from './H5Api';
import * as AdapterConstant from '../constants/adapter';

//EM 客户端
export default class EmApi extends H5Api {

    constructor() {
        super();
        this.takePhoto = this.takePhoto.bind(this);
    }

    //拍照
    takePhoto() {
        if (EmSDK.judgeApiSupport('chooseImage')) {
            EmSDK.takePhoto();
        }
    }

    //手写签批
    handleWriting(showDot){
        if(EmSDK.judgeApiSupport('handleWriting')){
            EmSDK.handleWriting(showDot);
        }
    }

    //全文批注
    editImage(){
        if(EmSDK.judgeApiSupport('editImage')){
            EmSDK.editImage();
        }
    }

    //em 录音
    voice(){
        if(EmSDK.judgeApiSupport('getAudioRecord')){
            EmSDK.audioRecord();
        }
    }

    // //获取位置
    // getLocation(locationdata){
    //     EmSDK.locationList(locationdata);
    // }

    //语音转文字
    speechTotext(){
        EmSDK.speechTotext();
    }

    // //查看位置
    // openLocation(params = {}){
    //     EmSDK.openLocation(params);
    // }

    judgeApiSupport(api = '') {
        switch (api){
            case AdapterConstant.API_TAKE_PHOTO:
                return false;//EmSDK.judgeApiSupport('chooseImage');
            case AdapterConstant.API_HANDLE_WRITING:
                return EmSDK.judgeApiSupport('handleWriting');
            case AdapterConstant.API_EDIT_IMAGE:
                return EmSDK.judgeApiSupport('editImage');
            case AdapterConstant.API_VOICE:
                return EmSDK.judgeApiSupport('getAudioRecord');
            case AdapterConstant.API_POSITION:
                return EmSDK.judgeApiSupport('getLocationList');
            case AdapterConstant.API_OPEN_LOCATION:
                return EmSDK.judgeApiSupport('openLocation');
            case AdapterConstant.API_SPEECH_TO_TEXT:
                return EmSDK.judgeApiSupport('speechTotext');
            default:
                return super.judgeApiSupport(api);
        }
    }
}